'use strict'

module.exports = async (c, next) => {

  let ctype = c.headers['content-type'] || '';

  try {
    if (ctype === 'text/json') {
      c.body = JSON.parse(c.body);
    } else if (ctype === 'application/json') {
      c.body = JSON.parse(c.body.toString('utf8'));
    }
  } catch (err) {
    c.status(400).send('bad data');
  }

  await next();

}